package com.hsq.db137.demos.controller;

import com.hsq.db137.demos.config.R;
import com.hsq.db137.demos.entity.Userrole;
import com.hsq.db137.demos.seriver.UserroleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: hsq加油
 * @CreateTime: 2024/12/25-17:11
 * @Description: TODO
 * @Version: 1.0
 */
@RestController
@CrossOrigin(origins = "*")
public class UserroleController {
    @Autowired
    UserroleService userroleService;

    /**
     * 根据用户ID和角色ID查询用户角色是否重复
//     * @param userrole 用具角色表
     * @return 提示语句
     */
    @GetMapping("selectByRoleidAndUserid")
    public boolean selectByRoleidAndUserid( int roleid, int userid){
        System.out.println("userrole.getUserid() = " + roleid);
        System.out.println("userrole.getRoleid() = " + userid);
        return userroleService.selectByRoleidAndUserid(roleid,userid);
    }

    /**
     * 根据用户ID和角色ID删除这个用户的角色
     * @param userrole 用户角色类
     * @return 提示语句
     */
    @PostMapping("delebyUseridAndRoleid")
    public R delebyUseridAndRoleid(@RequestBody Userrole userrole) {
       String msg= userroleService.delebyUseridAndRoleid(userrole);
        System.out.println("userrole.getRoleid() = " + userrole.getRoleid());
        System.out.println("userrole.getUserid() = " + userrole.getUserid());
        return new R().add("msg",msg);
    }


    /**
     * 新镇用户角色表
     *
     * @param userrole 类
     * @return 提示语句
     */
    @PostMapping("insertUserrole")
    public String insertUserrole(@RequestBody Userrole userrole) {
        return userroleService.insertUserrole(userrole);
    }
}
